//
//  CLProfileInfo.m
//  toroBracelet
//
//  Created by 丁益 on 16/7/20.
//  Copyright © 2016年 celi. All rights reserved.
//  用户账号信息

#import "CLProfileInfo.h"
#import "CLSeverTool.h"
#import "UIImage+Fit.h"

@implementation CLProfileInfo

SingletonM(ProfileInfo)

- (NSString *)country{

    if (_country == nil) {
        return @"中国";
    }
    return _country;
}


- (NSInteger)maxGoalStep{

    return 50000;
}
- (NSInteger)minGoalStep{

    return 3000;
}

- (NSString*)area{

    if (_area == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"area"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"area"];
    }
    return _area;
    
}

- (BOOL)setAreaAndCache:(NSString *)area{
    _area = area;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:area forKey:@"area"];
    return [dict writeToFile:filePath atomically:YES];
}


- (NSString *)sex{
    if (_sex == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"sex"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"sex"];
    }
    return _sex;
}
- (BOOL)setSexAndCache:(NSString *)sex{
    _sex = sex;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:sex forKey:@"sex"];
    return [dict writeToFile:filePath atomically:YES];
}



- (UIImage*)iconLarger{

    if (_iconLarger == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"iconLarger"] == nil) {
            return [UIImage imageNamed:@"阿狸头像"];
        }
        return [UIImage imageWithData:[dict objectForKey:@"iconLarger"]];
    }
    return _iconLarger;
}

- (BOOL)setIconLargerAndCache:(UIImage *)iconLarger{

    _iconLarger = iconLarger;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    NSData *imageDate = [UIImage imageToDate:iconLarger];
    [dict setObject:imageDate forKey:@"iconLarger"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString*)userName{
    if (_userName == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"userName"] == nil) {
            return @"爱吃土豆";
        }
        return [dict objectForKey:@"userName"];
    }
    return _userName;
}
- (BOOL)setUserNameAndCache:(NSString *)userName{

    _userName = userName;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:userName forKey:@"userName"];
    return [dict writeToFile:filePath atomically:YES];
}



- (NSString*)goalStep{
    if (_goalStep == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"goalStep"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"goalStep"];
    }
    return _goalStep;
}
- (BOOL)setGoalStepAndCache:(NSString *)goalStep{
    
    _goalStep = goalStep;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:goalStep forKey:@"goalStep"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString *)goalSleep{
    if (_goalSleep == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"goalSleep"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"goalSleep"];
    }
    return _goalSleep;
}

- (BOOL)setGoalSleepAndCache:(NSString *)goalSleep{

    _goalSleep = goalSleep;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:goalSleep forKey:@"goalSleep"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString*)phoneNumber{
    if (_phoneNumber == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"phoneNumber"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"phoneNumber"];
    }
    return _phoneNumber;
}
- (BOOL)setPhoneNumberAndCache:(NSString *)phoneNumber{
    
    _phoneNumber = phoneNumber;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:phoneNumber forKey:@"phoneNumber"];
    return [dict writeToFile:filePath atomically:YES];
}

- (BOOL)isBindingDevice{
    
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    if ([dict objectForKey:@"isBindingDeviceStats"] == nil) {
        return NO;
    }
    return [[dict objectForKey:@"isBindingDeviceStats"] integerValue];
}
- (BOOL)setIsBindingDeviceAndCache:(BOOL)isBindingDeviceStats{
    
    _isBindingDevice = isBindingDeviceStats;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:@(isBindingDeviceStats) forKey:@"isBindingDeviceStats"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString*)weight{

    if (_weight == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"weight"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"weight"];
    }
    return _weight;
}
- (BOOL)setWeightAndCache:(NSString *)weight{

    _weight = weight;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    DLog(@"filePath = %@",filePath);
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:weight forKey:@"weight"];
    return [dict writeToFile:filePath atomically:YES];
}


- (NSString*)uuidString{
    
    if (_uuidString == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"uuidString"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"uuidString"];
    }
    return _uuidString;
}
- (BOOL)setUuidStringAndCache:(NSString *)uuidString {

    _uuidString = uuidString;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:_uuidString forKey:@"uuidString"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString*)birthday{
    if (_birthday == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"birthday"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"birthday"];
    }
    return _birthday;
}
- (BOOL)setBirthdayAndCache:(NSString *)birthday{

    _birthday = birthday;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:birthday forKey:@"birthday"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString*)stature{
    if (_stature == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"stature"] == nil) {
            return CLLocalizedString(@"NotSet", nil);
        }
        return [dict objectForKey:@"stature"];
    }
    return _stature;
}
- (BOOL)setStatureAndCache:(NSString *)stature{
    
    _stature = stature;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:stature forKey:@"stature"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString*)securityKEY{

    if (_securityKEY == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"securityKEY"] == nil) {
            return nil;
        }
        return [dict objectForKey:@"securityKEY"];
    }
    return _securityKEY;
}
- (BOOL)setSecurityKEYAndCache:(NSString *)securityKEY{
    _securityKEY = securityKEY;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:securityKEY forKey:@"securityKEY"];
    return [dict writeToFile:filePath atomically:YES];
}



@end
